package com.test.orderservice.Controller;

import com.test.orderservice.Pojo.OrderInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RequestMapping("order")
@RestController
@Slf4j
public class RabbitController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public RabbitController(ConnectionFactory connectionFactory) {
    }

    @RequestMapping("create")
    public void create() {
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setMessage("hello world");
        orderInfo.setOrderId(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend("", "order", orderInfo);
        log.info("发送消息完毕...");
    }
}
